package com.halixun.d2app.adapter.holder;

import android.view.View;
import android.widget.TextView;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.HomeNavigationAdapter;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.bean.FoodCategoryInfo;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter.holder
 * @ClassName: HomeNavigationViewHolder
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/14 10:30
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/14 10:30
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class HomeNavigationViewHolder extends BaseViewHolder<FoodCategoryInfo> {

    private TextView category;

    private HomeNavigationAdapter.HomeNavigationListener mListener;

    public HomeNavigationViewHolder(View itemView) {
        super(itemView);
        initView();
        setListeners();
    }

    public HomeNavigationViewHolder(View itemView, HomeNavigationAdapter.HomeNavigationListener listener) {
        this(itemView);
        this.mListener = listener;
    }

    private void setListeners() {
        itemView.setOnClickListener(v -> {
            if (null!=mListener){
                mListener.onHomeNavigationListener(getAdapterPosition());
            }
        });
    }

    private void initView() {
        category = itemView.findViewById(R.id.category);
    }

    @Override
    public void setLayoutInfo(FoodCategoryInfo info) {
        category.setText(info.getClassName());
        category.setBackgroundResource(info.isSelected()?R.drawable.home_navigation_selected_shape:R.drawable.home_navigation_unselected_shape);
    }
}
